/**************************
* @Summary
* @Author 20009200303 赵传博
* @Date 2022/4/27
*****************************/

#include "Expr.h"

Expr::Expr(const char *str) {
    auto* parser = Parser::getInstance();
    root = parser->parse_expr(str);
}

double Expr::calculateVal() {
    if(root) return root->calculate();
    return 0;
}

void Expr::print_mid() {
    root->getText_mid();
    cout << txt << endl;
    txt.clear();
}

void Expr::print_postfix() {
    root->getText_postfix();
    cout << txt << endl;
    txt.clear();
}

void Expr::print_prefix() {
    root->getText_prefix();
    cout << txt << endl;
    txt.clear();
}

ExprNode *Expr::getRoot() const {
    return root;
}




